﻿// <copyright file="ProductIconHelper.cs" company="Snowman Consulting">
//     Copyright (c) 2009 Snowman Consulting. All rights reserved.
// </copyright>

namespace SnowmanConsulting.ProductKeyManager.Data
{
    using System;
    using System.Windows.Media.Imaging;

    /// <summary>
    /// Icon helper class
    /// </summary>
    public static class ProductIconHelper
    {
        #region Constants

        /// <summary>
        /// Generic application icon
        /// </summary>
        internal const string GenericApplication = "../Icons/Generic_Application.ico";

        /// <summary>
        /// Generic device icon
        /// </summary>
        internal const string GenericDevice = "../Icons/Generic_Device.ico";

        /// <summary>
        /// Generic Document icon
        /// </summary>
        internal const string GenericDocument = "../Icons/Generic_Document.ico";

        /// <summary>
        /// Auto List icon
        /// </summary>
        internal const string AutoList = "../Icons/autoList.ico";

        /// <summary>
        /// Autorun icon
        /// </summary>
        internal const string Autorun = "../Icons/autorun.ico";

        /// <summary>
        /// Command icon
        /// </summary>
        internal const string Cmd = "../Icons/cmd.ico";

        /// <summary>
        /// Computer icon
        /// </summary>
        internal const string Computer = "../Icons/computer.ico";

        /// <summary>
        /// Favorites Icon
        /// </summary>
        internal const string Favorites = "../Icons/Favorites.ico";

        /// <summary>
        /// Gear icon url
        /// </summary>
        internal const string Gear = "../Icons/Gear.ico";

        /// <summary>
        /// Globe icon
        /// </summary>
        internal const string Globe = "../Icons/Globe.ico";

        /// <summary>
        /// Journal icon
        /// </summary>
        internal const string Journal = "../Icons/journal.ico";

        /// <summary>
        /// Keys Icon url
        /// </summary>
        internal const string Keys = "../Icons/Keys.ico";

        /// <summary>
        /// Laptop icon
        /// </summary>
        internal const string Laptop = "../Icons/Laptop.ico";

        /// <summary>
        /// Monitor icon
        /// </summary>
        internal const string Monitor = "../Icons/Monitor.ico";

        /// <summary>
        /// Personalization icon
        /// </summary>
        internal const string Personalization = "../Icons/personalization.ico";

        /// <summary>
        /// VPN Icon url
        /// </summary>
        internal const string VPN = "../Icons/VPN.ico";

        /// <summary>
        /// Security lock icon
        /// </summary>
        internal const string SecurityLock = "../Icons/SecurityLock.ico";

        #endregion

        /// <summary>
        /// Gets the generic application icon.
        /// </summary>
        /// <value>The generic application icon.</value>
        public static ProductIcon GenericApplicationIcon
        {
            get
            {
                return new ProductIcon(ProductIconHelper.GenericApplication);
            }
        }

        /// <summary>
        /// Gets the generic device icon.
        /// </summary>
        /// <value>The generic device icon.</value>
        public static ProductIcon GenericDeviceIcon
        {
            get
            {
                return new ProductIcon(ProductIconHelper.GenericDevice);
            }
        }

        /// <summary>
        /// Gets the generic document icon.
        /// </summary>
        /// <value>The generic document icon.</value>
        public static ProductIcon GenericDocumentIcon
        {
            get
            {
                return new ProductIcon(ProductIconHelper.GenericDocument);
            }
        }

        /// <summary>
        /// Creates the product icon.
        /// </summary>
        /// <param name="iconUri">The icon URI.</param>
        /// <returns>a new product icon</returns>
        public static ProductIcon CreateProductIcon(string iconUri)
        {
            if (!string.IsNullOrEmpty(iconUri))
            {
                return ProductIconHelper.CreateProductIcon(new Uri(iconUri, UriKind.RelativeOrAbsolute));
            }

            return null;
        }

        /// <summary>
        /// Creates the product icon.
        /// </summary>
        /// <param name="iconUri">The icon URI.</param>
        /// <returns>a new product icon</returns>
        public static ProductIcon CreateProductIcon(Uri iconUri)
        {
            return new ProductIcon(iconUri.ToString());
        }

        /// <summary>
        /// Loads the default icons.
        /// </summary>
        /// <param name="icons">The icons.</param>
        public static void LoadDefaultIcons(ProductIconCollection icons)
        {
            string[] includedIcons = new string[] 
            {
                ProductIconHelper.GenericApplication,
                ProductIconHelper.GenericDevice,
                ProductIconHelper.GenericDocument,
                ProductIconHelper.AutoList,
                ProductIconHelper.Autorun,
                ProductIconHelper.Cmd,
                ProductIconHelper.Computer,
                ProductIconHelper.Favorites,
                ProductIconHelper.Gear,
                ProductIconHelper.Globe,
                ProductIconHelper.Journal,
                ProductIconHelper.Keys,
                ProductIconHelper.Laptop,
                ProductIconHelper.Monitor,
                ProductIconHelper.Personalization,
                ProductIconHelper.VPN,
                ProductIconHelper.SecurityLock
            };

            foreach (string icon in includedIcons)
            {
                icons.Add(new ProductIcon { IconUrl = icon });
            }
        }

        /// <summary>
        /// Loads the image.
        /// </summary>
        /// <param name="imageUri">The image URI.</param>
        /// <returns>A bitmap image from the specified URI</returns>
        public static BitmapImage LoadImage(Uri imageUri)
        {
            BitmapImage bitmap = new BitmapImage();
            bitmap.BeginInit();
            bitmap.UriSource = imageUri;
            bitmap.EndInit();

            return bitmap;
        }
    }
}
